﻿<UserControl x:Class="ViewTableEditor"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xml:lang="fr-FR"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="500">

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="5" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="5" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <GridSplitter Grid.Row="1" Grid.ColumnSpan="3" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
        <GridSplitter Grid.Column="1" Grid.Row="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />


        <GroupBox Grid.Row="2" Header="Variables de Segmentation">
            <ListBox ItemsSource="{Binding SegmentationVariables}" >
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Grid Margin="5">
                            <TextBlock HorizontalAlignment="Left" Text="{Binding Name}" />
                            <Button Content="  +  " HorizontalAlignment="Right" Command="{Binding}" />
                        </Grid>
                    </DataTemplate>
                </ListBox.ItemTemplate>
                <ListBox.ItemContainerStyle>
                    <Style TargetType="ListBoxItem">
                        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                        <Setter Property="HorizontalAlignment" Value="Stretch" />
                        <Setter Property="Visibility">
                            <Setter.Value>
                                <Binding Path="UnUsed">
                                    <Binding.Converter>
                                        <BooleanToVisibilityConverter />
                                    </Binding.Converter>
                                </Binding>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </ListBox.ItemContainerStyle>

            </ListBox>
        </GroupBox>
        <GroupBox Grid.Row="2" Grid.Column="2" Header="Table" >
            <DataGrid ItemsSource="{Binding EditionData}" ClipboardCopyMode="IncludeHeader" Name="DGrid" CanUserAddRows="False" CanUserDeleteRows="False" CanUserReorderColumns="False">
                <DataGrid.ColumnHeaderStyle>
                    <Style TargetType="DataGridColumnHeader" >
                        <Setter Property="HorizontalAlignment" Value="Stretch" />
                        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                        <Setter Property="Background" Value="White" />
                        <Setter Property="ContentTemplate" >
                            <Setter.Value>
                                <DataTemplate>  
                                    <Grid>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="*" />
                                            <ColumnDefinition Width="Auto" />
                                        </Grid.ColumnDefinitions>
                                  
                                        <TextBlock Grid.Column="0" Margin="2" VerticalAlignment="Center"   Text="{Binding}" />
                                        <Button Grid.Column="1" Margin="2"   Content=" X " VerticalAlignment="Center" Background="White" CommandParameter="{Binding}" Command="{Binding RelativeSource={RelativeSource AncestorType=DataGrid}, Path=DataContext.DeleteVariableCommand}" />
                                    </Grid>
                                  
                                </DataTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </DataGrid.ColumnHeaderStyle>
            </DataGrid>
        </GroupBox>
        <GroupBox Header="Filtres" Grid.ColumnSpan="3" >
            <ListBox ItemsSource="{Binding Filters}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal"  >
                            <ComboBox Name="cbxvar" MinWidth="50" Margin="5" ItemsSource="{Binding Variables}"  SelectedItem="{Binding Path=Variable, Mode=TwoWay}">
                                <ComboBox.ItemTemplate>
                                    <DataTemplate >
                                        <TextBlock Text="{Binding Name}" />
                                    </DataTemplate>
                                </ComboBox.ItemTemplate>
                            </ComboBox>
                            <ComboBox MinWidth="50" Margin="5" ItemsSource="{Binding Operators}" SelectedItem="{Binding Path=Operator, Mode=TwoWay}"/>
                            <ComboBox MinWidth="50" Margin="5" ItemsSource="{Binding ElementName=cbxvar, Path=SelectedItem.Values}" SelectedItem="{Binding Path=Value, Mode=TwoWay}"/>
                            <ComboBox MinWidth="50"  Margin="5" ItemsSource="{Binding FilterOperators}" SelectedItem="{Binding Path=FilterOperator, Mode=TwoWay}"/>
                            <Button Content="+" Margin="5" Width="20" Height="20" Command="{Binding}" CommandParameter="addnew"/>
                            <Button Content="X" Margin="5" Width="20" Height="20" Command="{Binding}" CommandParameter="delete"/>

                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
                <ListBox.ItemContainerStyle>
                    <Style TargetType="ListBoxItem">
                        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                        <Setter Property="HorizontalAlignment" Value="Stretch" />
                    </Style>
                </ListBox.ItemContainerStyle>

            </ListBox>

        </GroupBox>
    </Grid>
</UserControl>
